package com.yanxu.threadexception;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/1/18-2025
 * @Description: 堆栈信息打印
 */
public class APrintExceptionInfo {
    public static void main1 (String[] args) {
        try {
            for (int i = 0; i < 100; i++) {
                System.out.println(i);
            }
            int i=100/0;
        } catch (Exception e) {
            e.printStackTrace();
        }

        //打印出的线程堆栈信息
        //java.lang.ArithmeticException: / by zero
        //at com.yanxu.threadexception.PrintExceptionInfo.main(PrintExceptionInfo.java:15)
    }

    public static void main2 (String[] args) {
        try {
            for (int i = 0; i < 100; i++) {
                System.out.println(i);
            }
            int i=100/0;
        } catch (Exception e) {
            System.out.println("出现异常了!!!");
        }

        //错误的信息
        //出现异常了!!!
    }


    public static void main (String[] args) {
        for (int i = 0; i < 100; i++) {
            System.out.println(i);
        }
        int i=100/0;

        //打印出的线程堆栈信息 (使用了线程默认的  UncaughtExceptionHandler )
        //Exception in thread "main" java.lang.ArithmeticException: / by zero
        //at com.yanxu.threadexception.PrintExceptionInfo.main(PrintExceptionInfo.java:37)
    }
}